{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c33bc755",
   "metadata": {},
   "source": [
    "----------\n",
    "2022春 《交互式数据可视化》/《Interactive Data Visualization》 week15\n",
    "\n",
    "主讲 许智超\n",
    "\n",
    "时间：2022.06.08\n",
    "\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b45e935d",
   "metadata": {},
   "source": [
    "# 本周知识点-地图绘制\n",
    "\n",
    "## Pyecharts 绘制地图\n",
    "### 基本掌握输出方式\n",
    "\n",
    "> 1. render(\"map_base.html\")\n",
    "> 2. [render_notebook渲染在notebook](https://pyecharts.org/#/zh-cn/notebook)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ede4d4b3",
   "metadata": {},
   "source": [
    "## Map - Map_base"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5d4eed8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/xuzhichao/anaconda3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"2488cbb500d143e488967d51573a0032\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_2488cbb500d143e488967d51573a0032 = echarts.init(\n",
       "                    document.getElementById('2488cbb500d143e488967d51573a0032'), 'white', {renderer: 'canvas'});\n",
       "                var option_2488cbb500d143e488967d51573a0032 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5546\\u5bb6A\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 129\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 113\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 32\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 48\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 46\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 82\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 70\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"zoom\": 1,\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5546\\u5bb6A\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5546\\u5bb6A\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Map-\\u57fa\\u672c\\u793a\\u4f8b\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_2488cbb500d143e488967d51573a0032.setOption(option_2488cbb500d143e488967d51573a0032);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fa120aa4c50>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Map()\n",
    "    .add(\"商家A\", [list(z) for z in zip(Faker.provinces, Faker.values())], \"china\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"Map-基本示例\")\n",
    "    )\n",
    "#     .render(\"map_base.html\")\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00133754",
   "metadata": {},
   "source": [
    "### 检查各项参数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a14b89f7",
   "metadata": {},
   "source": [
    "#### Faker.provinces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bf21394a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广东', '北京', '上海', '江西', '湖南', '浙江', '江苏']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Faker.provinces"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddef5332",
   "metadata": {},
   "source": [
    "#### Faker.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d821064",
   "metadata": {},
   "outputs": [],
   "source": [
    "Faker.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e416684d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['广东', 68],\n",
       " ['北京', 37],\n",
       " ['上海', 48],\n",
       " ['江西', 133],\n",
       " ['湖南', 120],\n",
       " ['浙江', 41],\n",
       " ['江苏', 145]]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[list(z) for z in zip(Faker.provinces, Faker.values())]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a5477e0",
   "metadata": {},
   "source": [
    "#### Map\n",
    "[map_filename](https://github.com/pyecharts/pyecharts/blob/master/pyecharts/datasets/map_filename.json)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b82720d1",
   "metadata": {},
   "source": [
    "## Map - Map_guangdong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "6ee4fe54",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/xuzhichao/anaconda3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '广东':'https://assets.pyecharts.org/assets/maps/guangdong'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"414b93de92704094b931d2ddae70e047\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '广东'], function(echarts) {\n",
       "                var chart_414b93de92704094b931d2ddae70e047 = echarts.init(\n",
       "                    document.getElementById('414b93de92704094b931d2ddae70e047'), 'white', {renderer: 'canvas'});\n",
       "                var option_414b93de92704094b931d2ddae70e047 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5546\\u5bb6A\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"\\u5e7f\\u4e1c\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u6c55\\u5934\\u5e02\",\n",
       "                    \"value\": 145\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c55\\u5c3e\\u5e02\",\n",
       "                    \"value\": 116\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u63ed\\u9633\\u5e02\",\n",
       "                    \"value\": 127\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9633\\u6c5f\\u5e02\",\n",
       "                    \"value\": 127\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8087\\u5e86\\u5e02\",\n",
       "                    \"value\": 74\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u5dde\\u5e02\",\n",
       "                    \"value\": 58\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u60e0\\u5dde\\u5e02\",\n",
       "                    \"value\": 88\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"zoom\": 1,\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5546\\u5bb6A\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5546\\u5bb6A\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Map-\\u5e7f\\u4e1c\\u5730\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 140,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_414b93de92704094b931d2ddae70e047.setOption(option_414b93de92704094b931d2ddae70e047);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fa1237fcc10>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Map()\n",
    "    .add(\"商家A\", [list(z) for z in zip(Faker.guangdong_city, Faker.values())], \"广东\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"Map-广东地图\"), \n",
    "        visualmap_opts=opts.VisualMapOpts()\n",
    "    )\n",
    "#     .render(\"map_guangdong.html\")\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c95101e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "59b79cc8",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/xuzhichao/anaconda3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    }
   ],
   "source": [
    "# 导入库\n",
    "import requests\n",
    "import json\n",
    "import pyecharts\n",
    "from pyecharts.commons.utils import JsCode\n",
    "from pyecharts.globals import ChartType, _CurrentConfig\n",
    "from pyecharts.charts import Map, Page\n",
    "from pyecharts import options as opts\n",
    "\n",
    "\n",
    "# 自定义header\n",
    "header = {\n",
    "    'Host': 'news.qq.com/zt2020/page/feiyan.htm#/global',\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3704.400 QQBrowser/10.4.3587.400',\n",
    "}\n",
    "\n",
    "\n",
    "# 获取json数据\n",
    "def get_data(url):\n",
    "    get_data = requests.get(url, header)\n",
    "    json_data = json.dumps(get_data.json()['data'])\n",
    "    json_data = json.loads(json_data)\n",
    "    return json_data\n",
    "\n",
    "\n",
    "# 世界疫情地图\n",
    "def world_map(data):\n",
    "\n",
    "    # 国家名\n",
    "    National_data = []\n",
    "    # 确诊数据\n",
    "    num_data = []\n",
    "    # 治愈数据\n",
    "    num_data_zy = []\n",
    "    # 较上日\n",
    "    day_data = []\n",
    "    for i in range((len(data))):\n",
    "        National_data.append(data[i]['name'])\n",
    "        num_data.append(data[i]['confirm'])\n",
    "        num_data_zy.append(data[i]['heal'])\n",
    "        day_data.append(data[i]['confirmAdd'])\n",
    "\n",
    "    nameMap = {\n",
    "        'Singapore Rep.': '新加坡',\n",
    "        'Dominican Rep.': '多米尼加',\n",
    "        'Palestine': '巴勒斯坦',\n",
    "        'Bahamas': '巴哈马',\n",
    "        'Timor-Leste': '东帝汶',\n",
    "        'Afghanistan': '阿富汗',\n",
    "        'Guinea-Bissau': '几内亚比绍',\n",
    "        \"Côte d'Ivoire\": '科特迪瓦',\n",
    "        'Siachen Glacier': '锡亚琴冰川',\n",
    "        \"Br. Indian Ocean Ter.\": '英属印度洋领土',\n",
    "        'Angola': '安哥拉',\n",
    "        'Albania': '阿尔巴尼亚',\n",
    "        'United Arab Emirates': '阿联酋',\n",
    "        'Argentina': '阿根廷',\n",
    "        'Armenia': '亚美尼亚',\n",
    "        'French Southern and Antarctic Lands': '法属南半球和南极领地',\n",
    "        'Australia': '澳大利亚',\n",
    "        'Austria': '奥地利',\n",
    "        'Azerbaijan': '阿塞拜疆',\n",
    "        'Burundi': '布隆迪',\n",
    "        'Belgium': '比利时',\n",
    "        'Benin': '贝宁',\n",
    "        'Burkina Faso': '布基纳法索',\n",
    "        'Bangladesh': '孟加拉国',\n",
    "        'Bulgaria': '保加利亚',\n",
    "        'The Bahamas': '巴哈马',\n",
    "        'Bosnia and Herz.': '波斯尼亚和黑塞哥维那',\n",
    "        'Belarus': '白俄罗斯',\n",
    "        'Belize': '伯利兹',\n",
    "        'Bermuda': '百慕大',\n",
    "        'Bolivia': '玻利维亚',\n",
    "        'Brazil': '巴西',\n",
    "        'Brunei': '文莱',\n",
    "        'Bhutan': '不丹',\n",
    "        'Botswana': '博茨瓦纳',\n",
    "        'Central African Rep.': '中非',\n",
    "        'Canada': '加拿大',\n",
    "        'Switzerland': '瑞士',\n",
    "        'Chile': '智利',\n",
    "        'China': '中国',\n",
    "        'Ivory Coast': '象牙海岸',\n",
    "        'Cameroon': '喀麦隆',\n",
    "        'Dem. Rep. Congo': '刚果民主共和国',\n",
    "        'Congo': '刚果',\n",
    "        'Colombia': '哥伦比亚',\n",
    "        'Costa Rica': '哥斯达黎加',\n",
    "        'Cuba': '古巴',\n",
    "        'N. Cyprus': '北塞浦路斯',\n",
    "        'Cyprus': '塞浦路斯',\n",
    "        'Czech Rep.': '捷克',\n",
    "        'Germany': '德国',\n",
    "        'Djibouti': '吉布提',\n",
    "        'Denmark': '丹麦',\n",
    "        'Algeria': '阿尔及利亚',\n",
    "        'Ecuador': '厄瓜多尔',\n",
    "        'Egypt': '埃及',\n",
    "        'Eritrea': '厄立特里亚',\n",
    "        'Spain': '西班牙',\n",
    "        'Estonia': '爱沙尼亚',\n",
    "        'Ethiopia': '埃塞俄比亚',\n",
    "        'Finland': '芬兰',\n",
    "        'Fiji': '斐',\n",
    "        'Falkland Islands': '福克兰群岛',\n",
    "        'France': '法国',\n",
    "        'Gabon': '加蓬',\n",
    "        'United Kingdom': '英国',\n",
    "        'Georgia': '格鲁吉亚',\n",
    "        'Ghana': '加纳',\n",
    "        'Guinea': '几内亚',\n",
    "        'Gambia': '冈比亚',\n",
    "        'Guinea Bissau': '几内亚比绍',\n",
    "        'Eq. Guinea': '赤道几内亚',\n",
    "        'Greece': '希腊',\n",
    "        'Greenland': '格陵兰',\n",
    "        'Guatemala': '危地马拉',\n",
    "        'French Guiana': '法属圭亚那',\n",
    "        'Guyana': '圭亚那',\n",
    "        'Honduras': '洪都拉斯',\n",
    "        'Croatia': '克罗地亚',\n",
    "        'Haiti': '海地',\n",
    "        'Hungary': '匈牙利',\n",
    "        'Indonesia': '印度尼西亚',\n",
    "        'India': '印度',\n",
    "        'Ireland': '爱尔兰',\n",
    "        'Iran': '伊朗',\n",
    "        'Iraq': '伊拉克',\n",
    "        'Iceland': '冰岛',\n",
    "        'Israel': '以色列',\n",
    "        'Italy': '意大利',\n",
    "        'Jamaica': '牙买加',\n",
    "        'Jordan': '约旦',\n",
    "        'Japan': '日本本土',\n",
    "        'Kazakhstan': '哈萨克斯坦',\n",
    "        'Kenya': '肯尼亚',\n",
    "        'Kyrgyzstan': '吉尔吉斯斯坦',\n",
    "        'Cambodia': '柬埔寨',\n",
    "        'Korea': '韩国',\n",
    "        'Kosovo': '科索沃',\n",
    "        'Kuwait': '科威特',\n",
    "        'Lao PDR': '老挝',\n",
    "        'Lebanon': '黎巴嫩',\n",
    "        'Liberia': '利比里亚',\n",
    "        'Libya': '利比亚',\n",
    "        'Sri Lanka': '斯里兰卡',\n",
    "        'Lesotho': '莱索托',\n",
    "        'Lithuania': '立陶宛',\n",
    "        'Luxembourg': '卢森堡',\n",
    "        'Latvia': '拉脱维亚',\n",
    "        'Morocco': '摩洛哥',\n",
    "        'Moldova': '摩尔多瓦',\n",
    "        'Madagascar': '马达加斯加',\n",
    "        'Mexico': '墨西哥',\n",
    "        'Macedonia': '马其顿',\n",
    "        'Mali': '马里',\n",
    "        'Myanmar': '缅甸',\n",
    "        'Montenegro': '黑山',\n",
    "        'Mongolia': '蒙古',\n",
    "        'Mozambique': '莫桑比克',\n",
    "        'Mauritania': '毛里塔尼亚',\n",
    "        'Malawi': '马拉维',\n",
    "        'Malaysia': '马来西亚',\n",
    "        'Namibia': '纳米比亚',\n",
    "        'New Caledonia': '新喀里多尼亚',\n",
    "        'Niger': '尼日尔',\n",
    "        'Nigeria': '尼日利亚',\n",
    "        'Nicaragua': '尼加拉瓜',\n",
    "        'Netherlands': '荷兰',\n",
    "        'Norway': '挪威',\n",
    "        'Nepal': '尼泊尔',\n",
    "        'New Zealand': '新西兰',\n",
    "        'Oman': '阿曼',\n",
    "        'Pakistan': '巴基斯坦',\n",
    "        'Panama': '巴拿马',\n",
    "        'Peru': '秘鲁',\n",
    "        'Philippines': '菲律宾',\n",
    "        'Papua New Guinea': '巴布亚新几内亚',\n",
    "        'Poland': '波兰',\n",
    "        'Puerto Rico': '波多黎各',\n",
    "        'Dem. Rep. Korea': '朝鲜',\n",
    "        'Portugal': '葡萄牙',\n",
    "        'Paraguay': '巴拉圭',\n",
    "        'Qatar': '卡塔尔',\n",
    "        'Romania': '罗马尼亚',\n",
    "        'Russia': '俄罗斯',\n",
    "        'Rwanda': '卢旺达',\n",
    "        'W. Sahara': '西撒哈拉',\n",
    "        'Saudi Arabia': '沙特阿拉伯',\n",
    "        'Sudan': '苏丹',\n",
    "        'S. Sudan': '南苏丹',\n",
    "        'Senegal': '塞内加尔',\n",
    "        'Solomon Is.': '所罗门群岛',\n",
    "        'Sierra Leone': '塞拉利昂',\n",
    "        'El Salvador': '萨尔瓦多',\n",
    "        'Somaliland': '索马里兰',\n",
    "        'Somalia': '索马里',\n",
    "        'Serbia': '塞尔维亚',\n",
    "        'Suriname': '苏里南',\n",
    "        'Slovakia': '斯洛伐克',\n",
    "        'Slovenia': '斯洛文尼亚',\n",
    "        'Sweden': '瑞典',\n",
    "        'Swaziland': '斯威士兰',\n",
    "        'Syria': '叙利亚',\n",
    "        'Chad': '乍得',\n",
    "        'Togo': '多哥',\n",
    "        'Thailand': '泰国',\n",
    "        'Tajikistan': '塔吉克斯坦',\n",
    "        'Turkmenistan': '土库曼斯坦',\n",
    "        'East Timor': '东帝汶',\n",
    "        'Trinidad and Tobago': '特里尼达和多巴哥',\n",
    "        'Tunisia': '突尼斯',\n",
    "        'Turkey': '土耳其',\n",
    "        'Tanzania': '坦桑尼亚',\n",
    "        'Uganda': '乌干达',\n",
    "        'Ukraine': '乌克兰',\n",
    "        'Uruguay': '乌拉圭',\n",
    "        'United States': '美国',\n",
    "        'Uzbekistan': '乌兹别克斯坦',\n",
    "        'Venezuela': '委内瑞拉',\n",
    "        'Vietnam': '越南',\n",
    "        'Vanuatu': '瓦努阿图',\n",
    "        'West Bank': '西岸',\n",
    "        'Yemen': '也门',\n",
    "        'South Africa': '南非',\n",
    "        'Zambia': '赞比亚',\n",
    "        'Zimbabwe': '津巴布韦',\n",
    "        'Dem.Rep.Congo': '刚果（金）',\n",
    "        'Congo': '刚果（布）',\n",
    "        'Central African Rep.': '中非共和国',\n",
    "        'Sudan': '苏丹',\n",
    "        'Greenland': '格陵兰岛',\n",
    "        'Bangladesh': '孟加拉'\n",
    "    }\n",
    "    # 国家中文名转为英文\n",
    "    for a in range(len(National_data)):\n",
    "        for b in nameMap.keys():\n",
    "            if National_data[a] == nameMap[b]:\n",
    "                National_data[a] = b\n",
    "            else:\n",
    "                continue\n",
    "    # 使用zip压缩为元组形式\n",
    "    qz_data = [tuple(z) for z in zip(National_data, num_data)]\n",
    "    zy_data = [tuple(z) for z in zip(National_data, num_data_zy)]\n",
    "    sr_data = [tuple(z) for z in zip(National_data, day_data)]\n",
    "\n",
    "    data_sum = 0\n",
    "    data_zy = 0\n",
    "    for i in range(len(num_data)):\n",
    "        data_sum += num_data[i]\n",
    "        data_zy += num_data_zy[i]\n",
    "    # 副标题\n",
    "    subtitle = \"确诊数量：\" + str(data_sum) + \"例\\n\\n治愈数量：\"+str(data_zy)+\"例\"\n",
    "    world_map_data = (\n",
    "        Map(\n",
    "            # 设置宽度，高度\n",
    "            init_opts={\"width\": \"1280px\", \"height\": \"800px\"}\n",
    "        )\n",
    "        .add(\n",
    "            \"确诊数量\",\n",
    "            qz_data,\n",
    "            maptype=\"world\",\n",
    "            is_selected=True,\n",
    "            is_map_symbol_show=False\n",
    "        )\n",
    "        .add(\n",
    "            \"治愈数量\",\n",
    "            zy_data,\n",
    "            maptype=\"world\",\n",
    "            is_selected=False,\n",
    "            is_map_symbol_show=False\n",
    "        )\n",
    "        .add(\n",
    "            \"较上日数量\",\n",
    "            sr_data,\n",
    "            maptype=\"world\",\n",
    "            is_selected=False,\n",
    "            is_map_symbol_show=False\n",
    "        )\n",
    "        # 系列配置\n",
    "        .set_series_opts(\n",
    "            # 不显示经纬度，设置颜色，字体大小\n",
    "            label_opts={'is_show': 'False',\n",
    "                        'color': '#fff', 'font_size': '18', 'position': 'left'},\n",
    "        )\n",
    "        # 全局配置\n",
    "        .set_global_opts(\n",
    "            # 视觉映射配置项\n",
    "            visualmap_opts=opts.VisualMapOpts(min_=0, max_=int(\n",
    "                data_sum / 50)),\n",
    "            # 设置左上角标题和副标题\n",
    "            title_opts=opts.TitleOpts(\n",
    "                title=\"世界疫情地图\", subtitle=subtitle, pos_left=\"50\", pos_top=\"5%\", title_textstyle_opts=opts.TextStyleOpts(font_size=30), subtitle_textstyle_opts=opts.TextStyleOpts(font_size=18, color='#222')\n",
    "            ),\n",
    "            # 图例设置\n",
    "            legend_opts=opts.LegendOpts(\n",
    "                selected_mode='single', pos_top=\"50\", pos_bottom=\"5%\", textstyle_opts=opts.TextStyleOpts(font_size=18)),\n",
    "        )\n",
    "        .render(\"疫情地图.html\")\n",
    "    )\n",
    "\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    # 世界疫情地图\n",
    "    QQ_data_url2 = 'https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist'\n",
    "    json_data2 = get_data(QQ_data_url2)\n",
    "    world_map(json_data2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "977cdf11",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
